//
//  TranitionAnimator.swift
//  Swift-app开发基础架构
//
//  Created by pro on 2017/8/16.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

import UIKit

// MARK: ------ 模态转场动画的控制者
class KZAnimator: NSObject, UIViewControllerTransitioningDelegate {

    /// 默认转场时间
    var toDuration = 0.5
    /// 默认返场时间
    var backDuration = 0.5

    /// 转场动画
    var toAnimation: KZAnimatedTransitioning?
    /// 返场动画
    var backAnimation: KZAnimatedTransitioning?

    /// 转场手势
    var toInteractive: KZInteractiveTransition?
    /// 返场手势
    var backInteractive: KZInteractiveTransition?
    
    // MARK: UIViewControllerTransitioningDelegate
    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        
        return toAnimation
    }
    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        
        return backAnimation
    }
    func interactionControllerForPresentation(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
        if toInteractive == nil {
            return nil
        } else {
            return toInteractive!.interation ? toInteractive : nil
        }
    }
    func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
        if backInteractive == nil {
            return nil
        } else {
            return backInteractive!.interation ? backInteractive : nil
        }
    }
    
}
